﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// GetTPB, Copyright Mirosław M. Mączka.  All Rights Reserved. This code released under the terms of the Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)
namespace GetTpb
{
    public class TpbItem2File
    {
        //
        //20:21:00|http://torrents.thepiratebay.org/4517772/Lush_-_All_Studio_Albums_(FLAC).4517772.TPB.torrent|1010,12|12|7|
        //
        public string Title { get; set; }
        Uri PageAddress { get; set; }
        DateTime Date { get; set; }
        Uri TorrentAddress { get; set; }
        public double Size { get; set; }
        public int Seeders { get; set; }
        public int Leechers { get; set; }
        //
        //
        //public bool TpbItem2File(string _Title, string _PageAddress, string _Date, string _TorrentAddress, string _Size, string _Seeders, string _Leechers)
        //{
            //
            //
            //return Add(_Title, _PageAddress, _Date, _TorrentAddress, _Size, _Seeders, _Leechers);
        //}
        //
        public bool Add(string _Title, string _PageAddress, string _Date, string _TorrentAddress, string _Size, string _Seeders, string _Leechers)
        {
            //
            try
            {
                //
                this.Title = _Title.Trim();
                //
                this.PageAddress = new Uri(_PageAddress);
                //
                this.Date = TpbUtils.FromPageDate2DT(_Date);
                //
                this.TorrentAddress = new Uri(_TorrentAddress);
                //
                this.Size = TpbUtils.FromPageSize2Dbl(_Size);
                //
                this.Seeders = TpbUtils.FromPage2Int(_Seeders);
                //
                this.Leechers = TpbUtils.FromPage2Int(_Leechers);
                //
            }
            catch (Exception e)
            {
                return false;
            }
            //
            return true;
        }
        //
        public string GetHtmlTableRow()
        {
            string s = "";
            //
            //<tr><td><font face="VERDANA"><a href="internet8/default.htm">Komputer internetowy na karcie CF</a></font></td></tr>
            s = "<tr>";
            //
            s += string.Format("<td><font face=\"VERDANA\"><a href=\"{1}\">{0}</a></font></td>", Title, PageAddress);
            s += string.Format("<td><font face=\"VERDANA\">{0}</font></td>",Date.ToString("yy-MM-dd HH:mm"));
            s += string.Format("<td><font face=\"VERDANA\"><a href=\"{0}\">Torrent</a></font></td>", TorrentAddress);
            s += string.Format("<td><font face=\"VERDANA\">{0}</font></td>",Size.ToString("N1"));
            s += string.Format("<td><font face=\"VERDANA\">{0}</font></td>",Seeders);
            s += string.Format("<td><font face=\"VERDANA\">{0}</font></td>", Leechers);
            //
            s += "</tr>";
            //
            return s;
        }
        //
        public static string GetHtmlBegin(string title)
        {
            string s = "";
            s += "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">";
            s += "<html>";
            s += "<head>";
            s += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>";
            s += "<title>" + title + "</title>";
            s += "<body>";
            s += "<center>";
            s += "<font face=\"tahoma\">";
            s += "<table border=\"2\" cellspacing=\"0\" cols=\"7\" width=\"80%\">";
            s += "<tbody>";
            return s;
        }
        //
        public static string GetHtmlEnd()
        {
            string s = "";
            s += "</tbody>";
            s += "</table>";
            s += "</font>";
            s += "</center>";
            s += "</body>";
            s += "</html>";
            return s;
        }
        //
        public override string ToString()
        {
            return string.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}|", Title, PageAddress, Date, TorrentAddress, Size, Seeders, Leechers);
        }
        //
    }//class
}//namespace
